package org.cloudie.docs.editor.client.feeds.docs;

import com.google.gwt.user.client.rpc.AsyncCallback;

/**
 * The async counterpart of the GData remote service.
 */
public interface FileServiceAsync {
  
  /**
   * Retrieves a file by Id.
   * 
   * @param fileId the file Id
   * @param callback the callback to invoke upon completion
   */
  void getFile(String fileId, AsyncCallback<FileServiceEntry> callback);
  
  /**
   * Retrieves a new, unsaved, file.
   * 
   * @param name the new file's name
   * @param callback the callback to invoke upon completion
   */
  void getNewFile(String name, AsyncCallback<FileServiceEntry> callback);
  
  /**
   * Retrieves the contents of a document by resource Id.
   * 
   * @param resourceId the resource Id
   * @param callback the callback to invoke upon completion
   */
  void getDocumentContents(String resourceId, AsyncCallback<String> callback);
  
  /**
   * Retrieves the contents of a spreadsheet by resource Id.
   * 
   * @param resourceId the resource Id
   * @param callback the callback to invoke upon completion
   */
  void getSpreadsheetContents(String resourceId, AsyncCallback<String> callback);
  
  /**
   * Retrieves the contents of a common document.
   * 
   * @param name the name of the document whose documents to retrieve
   * @param callback the callback to invoke upon completion
   */
  void getCommonContents(String name, AsyncCallback<String> callback);
  
  /**
   * Updates the contents of a document.
   * 
   * @param documentId the document Id
   * @param etag the document's version tag
   * @param contents the document contents
   * @param callback the callback to invoke upon completion
   */
  void setDocumentContents(String documentId, String etag, String contents, AsyncCallback<FileServiceEntry> callback);
  
  /**
   * Updates the contents of a spreadsheet.
   * 
   * @param spreadsheetId the spreadsheet Id
   * @param etag the document's version tag
   * @param contents the spreadsheet contents
   * @param callback the callback to invoke upon completion
   */
  void setSpreadsheetContents(String spreadsheetId, String etag, String contents, AsyncCallback<FileServiceEntry> callback);
  
  /**
   * Renames a file.
   * 
   * @param fileId the file Id
   * @param newName the new file name
   * @param callback the callback to invoke upon completion
   */
  void renameFile(String fileId, String newName, AsyncCallback<FileServiceEntry> callback);
  
  /**
   * Deletes a file.
   * 
   * @param fileId the file Id
   * @param etag the file's version tag
   * @param callback the callback to invoke upon completion
   */
  void deleteFile(String fileId, String etag, AsyncCallback<Boolean> callback);
  
  /**
   * Sets whether a file is starred.
   * 
   * @param fileId the file Id
   * @param starred whether the file is starred
   * @param callback the callback to invoke upon completion
   */
  void setFileStarred(String fileId, boolean starred, AsyncCallback<Boolean> callback);
  
  /**
   * Creates a new, saved, document.
   * 
   * @param title the document's title
   * @param contents the document's contents
   * @param callback the callback to invoke upon completion
   */
  void createDocument(String title, String contents, AsyncCallback<FileServiceEntry> callback);
  
  /**
   * Creates a new, saved, spreadsheet.
   * 
   * @param title the spreadsheet's title
   * @param contents the spreadsheet's contents
   * @param callback the callback to invoke upon completion
   */
  void createSpreadsheet(String title, String contents, AsyncCallback<FileServiceEntry> callback);
  
  /**
   * Updates or creates a new document. If a value for documentId is
   * specified, the respective document is updated, otherwise a new 
   * document is created.
   * 
   * @param documentId the document Id
   * @param etag the document's etag
   * @param title the document's title
   * @param contents the document's contents
   * @param callback the callback to invoke upon completion
   */
  void saveDocument(String documentId, String etag, String title, String contents, AsyncCallback<FileServiceEntry> callback);
  
  /**
   * Updates or creates a new spreadsheet. If a value for spreadsheetId is
   * specified, the respective spreadsheet is updated, otherwise a new 
   * spreadsheet is created.
   * 
   * @param spreadsheetId the spreadsheet Id
   * @param etag the spreadsheet's etag
   * @param title the spreadsheet's title
   * @param contents the spreadsheet's contents
   * @param callback the callback to invoke upon completion
   */
  void saveSpreadsheet(String spreadsheetId, String etag, String title, String contents, AsyncCallback<FileServiceEntry> callback);
  
  /**
   * Retrieves a list of a files.
   * 
   * @param starredOnly whether to return only starred files
   * @param searchTerm the term to search for in the file contents
   * @param callback the callback to invoke upon completion
   */
  void getFiles(boolean starredOnly, String searchTerm, AsyncCallback<FileServiceEntry[]> callback);
  
  /**
   * Retrieves the currently signed on user.
   * 
   * @param callback the callback to invoke upon completion
   */
  void getUser(AsyncCallback<FileUser> callback);
  
  void setUser(String email, String token, AsyncCallback<FileUser> callback);
  
  /**
   * Ends the current user's session
   * 
   * @param callback the callback to invoke upon completion
   */
  void logout(AsyncCallback<String> callback);
  
}
